<?php
global $_W, $_GPC;
$uid = $_GPC['uid'];
$sonid = $_GPC['sonid'];
$lessonid = $_GPC['lid'];
$weid = $_W['uniacid'];
if (empty($uid)) {
    return $this->getresult(1, '请先登录', array('code' => 3001, 'msg' => '请先登录'));
}
if (empty($lessonid)) {
    return $this->getresult(1, '请先选择课程', array('code' => 3001, 'msg' => '请先选择课程'));
}
if (empty($sonid)) {
    return $this->getresult(1, '请先选择章节', array('code' => 3001, 'msg' => '请先选择章节'));
}
/***校验token开始***/
if ($uid) {
    $token = $_GPC['token'];
    if (empty($token)) {
        return $this->getresult(1, '请重新登录', ['code' => 4001, 'msg' => '请重新登录']);
    }
    $token_result = $this->checktoken($uid, $token);
    if ($token_result == 1002) {
        return $this->getresult(1, '请重新登录', ['code' => 4002, 'msg' => '请重新登录']);
    } elseif ($token_result == 1003) {
        return $this->getresult(1, '请重新登录', ['code' => 4003, 'msg' => '请重新登录']);
    } elseif ($token_result == 1001) {
        //  更新token
        pdo_update($this->t_user_token, array('createtime' => time()), array('uid' => $uid, 'token' => $token, 'weid' => $_W['uniacid']));
    }
}
/***校验token结束***/
$params = array(':weid' => $weid, ':uid' => $uid, ':lessonid' => $lessonid, ':sonid' => $sonid);
$practiceRecord = pdo_fetchall("select * from " . tablename('goouc_class_practice_record') . "  where weid = :weid AND uid = :uid AND lessonid =:lessonid AND sonid=:sonid order by id desc limit 1", $params);
$record = unserialize($practiceRecord[0]['record']);
$types_config = array('1' => '判断题', '2' => '单选题', '3' => '多选题', '4' => '填空题');
$weid = $_W['uniacid'];
$paramsl = [':weid' => $weid, ':sonid' => $sonid, ':lessonid' => $lessonid, ':status' => 1];
$practiceList = pdo_fetchall("select * from " . tablename('goouc_class_practice') . "  where weid = :weid AND sonid = :sonid AND status = :status AND lessonid = :lessonid", $paramsl);
foreach ($practiceList as $k => &$v) {
    if ($v['thumb']) {
        $v['thumb'] = $this->getImgUrl($v['thumb']);
    }
    if ($v['type'] == 2 || $v['type'] == 3) {
        $v['items'] = unserialize($v['items']);
        if ($v['isimg'] == 1) {
            $img_items = unserialize($v['img_items']);
            foreach ($img_items as &$vi) {
                $vi['p'] = $this->getImgUrl($vi['p']);
            }
            $v['img_items'] = $img_items;
        }
    } elseif ($v['type'] == 4) {
        //计算填空数
        $v['answersNum'] = explode("、", $v['answer']);//这个该怎么计算
    }
    $v['practiceType'] = $types_config[$v['type']];
    //用户该题对错
    $v['userstatus'] = $record[$v['id']]['status'];
    $v['useranswer'] = $record[$v['id']]['uanswer'];
}
return $this->getresult(0, '解析详情', ['code' => 200, 'practiceList' => $practiceList]);